home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Tele
/
T
/
Telebit.cpt
/
New Telebit Modem
next >
Wrap
Text File
|
1988-07-06
|
23KB
|
701 lines
' ################################
' ## TELEBIT MODEM SERVICE FILE ##
' ################################
' Written by Lloyd Kreuzer, Kreuzer Software Corp.
' Revision, editing, and additions by Ken Walter
' TELEBIT modifications by Mike Smith, 6/20/88
' Last Modified 7/6/88
' Contains Identify, Dial, Configure, HangUp, ClearTable, and Interrupt routines
' for Hayes and Hayes-compatible modems
'********************************************************************************
Identify: ' This routine tells calling file that this is a modem file
'********************************************************************************
Message = "MODEM"
RETURN
'********************************************************************************
Dial: ' Inits modem, dials a number and tries to get on-line
'********************************************************************************
' Enter with phone numbers and modem settings in the system variable Message
' Each number and modem settings pair is separated by a ":"
' The number and modem settings are separated by "|".
' If there are no settings don't use a "|".
' No colon after last number
' For example: Message = "555-1212|1200,8,NO%,1,YES%:987-6543|2400,8,NO%,1,YES%"
HOLD ON ' for speed and no interrupts
' If service set @modemRedial%, set it to false and use next number in
' @modemNumbers, if @modemNumbers is not NIL, else use Message
IF @modemRedial% THEN ∂
@modemRedial% = FALSE%: ∂
IF @modemNumbers <> "" THEN Message = @modemNumbers
IF Message = "" THEN Message = "Dial called without a phone number.":RETURN
@modemNumbers = Message
' configure modem if necessary (@modemMaxBPS% is set if modem was configured)
IF @modemMaxBPS% = 0 THEN GOSUB Configure:HOLD ON
' init modem command strings
GOSUB quickModemCommands
' reset and initialize modem
GOSUB modemReset
dial1:
HOLD ON
CURSOR PHONE
' parse next number/settings pair from @modemNumbers
' find the colon
modemColon% = InStr%(@modemNumbers, ":")
' put first pair in modemPhoneNumber
' and, if there is a colon, put remaining numbers in @modemNumbers
IF modemColon% <> 0 THEN ∂
modemPhoneNumber = Left(@modemNumbers,(modemColon%-1)): ∂
@modemNumbers = Mid(@modemNumbers,(modemColon%+1)) ∂
ELSE ∂
modemPhoneNumber = @modemNumbers: ∂
@modemNumbers = ""
' find the start of the settings string, if any
modemBar% = InStr%(modemPhoneNumber,"|")
' separate settings from phone number and set default settings if no settings
IF modemBar% <> 0 THEN ∂
modemParams = Mid(modemPhoneNumber,(modemBar%+1)) : ∂
modemPhoneNumber = Left(modemPhoneNumber,(modemBar%-1)) ∂
ELSE modemParams = ""
' if we're out of phone numbers, then return
IF modemPhoneNumber = "" THEN ∂
Status = "Off Line": ∂
Message = "No Carrier.": ∂
CommC.RemEcho% = SaveRemEcho%: ∂ ' restore changed settings
CommC.DBits% = SaveDBits%: ∂
HOLD OFF: ∂
RETURN
'HOLD OFF
' set communications settings to settings passed in Message, if any
'For TELEBIT strip BPS off front and prefix with "19200" instead
'Also set xmitMode string to force PEP mode if in "Universal" mode and BPS >= 9600
xmitMode = "" 'Default is to leave s50 register alone
IF modemParams <> "" THEN ∂
requestedBPS% = val%(modemParams): ∂
modemParams = mid(modemParams, instr%(modemParams, ",")): ∂
modemParams = "19200" & modemParams: ∂
SET modemParams: ∂
if @modemInit = @modemInitUniv then ∂
if requestedBPS% >= 9600 then xmitMode = "255" ∂
else xmitMode = "0"
'HOLD ON
' Set up look-fors for carrier detect and errors
' If 3 string then try the next number
LOOK FOR "3" & modemCommEnd,1,1 THEN ∂
CLEAR DBOX 500: ∂
GOTO dial1 ' try next number
' If there is an error then tell user
LOOK FOR "4" & modemCommEnd,1,1 THEN ∂
CLEAR DBOX 500: ∂
Message = "Modem dial command error. " ∂
& "Please check phone number(s) and command strings and try again.": ∂
GOSUB modemFatalError: ∂
CURSOR PHONE: ∂
GOTO reDial ' Try again with same number
' Look for busy string (if any) and try next number
LOOK FOR "7" & modemCommEnd,1,1 THEN ∂
CLEAR DBOX 500: ∂
Status = "Busy": ∂
GOSUB quickHangUp: ∂
GOTO dial1 ' try next number
LOOK FOR "50^M",1,3 THEN HOLD ON:GOTO carrierPEP 'CONNECT FAST
LOOK FOR "10^M",1,3 THEN HOLD ON:GOTO carrierHayes 'CONNECT 2400
LOOK FOR "5^M", 1,3 THEN HOLD ON:GOTO carrierHayes 'CONNECT 1200
LOOK FOR "1^M", 1,3 THEN HOLD ON:GOTO carrierHayes 'CONNECT 300
reDial:
Status ="Dialing"
SET DBOX 500
ButtonText(2) = "Now calling " & modemPhoneNumber & "."
HOLD OFF
' set Transmission Mode
if xmitMode <> "" then ∂
send "at s50="; xmitMode: ∂
wait for "0" for 2
' dial the number
'{RTV 7/6/88}
IDLE 60
SEND @modemDialPre; modemPhoneNumber
DBOX 500 ' Wait for look-fors or user cancel
'{RTV 5/11/88}
waitWhileDialing:
IF DBoxResult% <> OK% THEN GOTO waitWhileDialing
HOLD ON ' User clicked "Cancel" button, so hang up and end
CLEAR DBOX 500
FORGET ALL
Message = ""
GOSUB quickHangUp
CommC.RemEcho% = SaveRemEcho% ' restore changed settings
CommC.DBits% = SaveDBits%
END
'If Fast XModem is checked and answered as CONNECT FAST then change to CRC XModem
'This is needed because TELEBIT's XModem spoof only works with 128 byte blocks
'If a Hayes is at other end and Fast XModem is checked then put back to 1K blocks XModem
'If FastXModem is not checked or TELEBIT to Hayes in selected then protocol is never changed
carrierPEP:
if (@modemMaxBPS% >= 9600) and @modemFastXModem% then ∂
CommC.ProtOpt% = 1
goto carrier
carrierHayes:
if (@modemMaxBPS% < 9600) and @modemFastXModem% then ∂
CommC.ProtOpt% = 2
carrier: 'carrier detected
CLEAR DBOX 500
TIMER RESET
TIMER START
CURSOR RESET
Status = "On Line"
PhoneNum = modemPhoneNumber
CommC.RemEcho% = SaveRemEcho% ' restore changed settings
CommC.DBits% = SaveDBits%
FORGET ALL
HOLD OFF
RETURN
'****************************************************************************
HangUp:
'****************************************************************************
' This routine hangs up the phone line and resets the modem
' It is normally called when the modem is on line but it can be
' called with the modem off line. In either case it will return
' with Message = "" and Status = "Off Line"
' if everything is OK or else produce a fatal error
HOLD ON ' for speed
STATUS = "Hanging Up"
IF @modemMaxBPS% = 0 THEN GOSUB configure
GOSUB quickHangUpCommands
quickHangUp: ' come here if command strings are inited
CURSOR PHONE
FORGET OFF
LOOK FOR "4" & modemCommEnd,1,1 THEN ∂
Message = "Invalid modem command string.":∂
GOSUB modemFatalError:∂
GOTO quickHangUp ' try again
LOOK FOR "0" & modemCommEnd,1,1 THEN ∂
IF modemHangUp% = FALSE% THEN WAIT 1:GOTO hangUp2 ∂
ELSE ∂
FORGET ALL:∂
FORGET ON: ∂
Status = "Off Line":∂
TIMER STOP:∂
CURSOR RESET:∂
Message = "" :∂
CommC.RemEcho% = SaveRemEcho%: ∂ ' restore changed settings
CommC.DBits% = SaveDBits%: ∂
RETURN
hangUpTries% = 1
HOLD OFF
hangUp1:
WAIT 1 'This is needed for TELEBIT,
IDLE 60 FOR 4
SEND "+++"; ' send escape
modemHangUp% = FALSE%
WAIT 1
hangUp2: ' send hang up string
modemHangUp% = TRUE%
IDLE 60 ' pause
SEND "ATH0"
WAIT 1 ' wait for look-fors
HOLD ON
' reset modem if hangup won't work
' init modem command strings needed for reset
GOSUB quickModemCommands
GOSUB modemReset
Status = "Off Line" ' will return only if reset is successful
Message = ""
CommC.RemEcho% = SaveRemEcho% ' restore changed settings
CommC.DBits% = SaveDBits%
TIMER STOP
CURSOR RESET
HOLD OFF
RETURN
'****************************************************************************
AutoAnswer: ' This routine puts the modem in autoanswer mode.
'****************************************************************************
HOLD ON
CURSOR PHONE
IF @modemMaxBPS% = 0 THEN GOSUB configure
GOSUB quickModemCommands 'Initialize variables
' Parse Message into modemAnswerRings and answerWait
' modemAnswerRings = number of rings modem waits before answering (Default is 1)
' modemAnswerWait = time modem waits for call (default is forever)
GOSUB parseAnswerMessage
answerWait% = VAL%(answerWait)
reAnswer:
'reset and initialize modem
GOSUB modemReset
HOLD ON
CURSOR PHONE
STATUS = "Auto-Answer Set-up"
' set up look-fors for auto-answer commands
'{RTV - 5/13/88 A Ring (2) may affect where the LOOK FOR is. Change to 1,5 vs. 1,1}
'{RTV - 7/6/88 Who knows where the cur pos will be - columns deleted}
'LOOK FOR "4" & modemCommEnd,1,5 THEN ∂
LOOK FOR "4" & modemCommEnd THEN ∂
FORGET ALL: ∂
Message = "Invalid modem command string.": ∂
GOSUB modemFatalError: ∂
GOTO reAnswer
'{RTV - 5/13/88 A Ring (2) may affect where the LOOK FOR is. Change to 1,5 vs. 1,1}
'{RTV - 7/6/88 Who knows where the cur pos will be - columns deleted}
'LOOK FOR "0" & modemCommEnd,1,5 THEN ∂
LOOK FOR "0" & modemCommEnd THEN ∂
FORGET ALL: ∂
HOLD ON: ∂
GOTO autoAnswerLookfors
HOLD OFF
'{RTV 7/6/88}
IDLE 60
SEND "ATS0="; modemAnswerRings
WAIT 2 ' wait for look-fors (error or OK)
Message = "Unable to set auto-answer mode."
GOSUB modemFatalError
GOTO reAnswer
autoAnswerLookfors:
' wait for a connect strings and set bps to that of calling computer
FORGET ALL
' If 3 then go back to auto-answer mode for until time-out or autoanswer
LOOK FOR "3" & modemCommEnd,1,1 THEN ∂
FORGET ALL: ∂
CLEAR DBOX 499: ∂
answerWait% = endTime% - Now%: ∂
GOTO reAnswer
LOOK FOR "4" & modemCommEnd THEN ∂
FORGET ALL: ∂
CLEAR DBOX 499: ∂
Message = "Modem dial command error.":∂
GOSUB modemFatalError:∂
GOTO reAnswer
' set up look fors for carrier according to maximum modem speed
modemGoto% = @modemMaxBPS% + 2
GOTO modemGoto%
19202: LOOK FOR "50^M",1,3 THEN HOLD ON:GOTO leaveAnswerPEP 'CONNECT FAST
2402: LOOK FOR "10^M",1,3 THEN HOLD ON:GOTO leaveAnswerHayes 'CONNECT 2400
1202: LOOK FOR "5^M", 1,3 THEN HOLD ON:GOTO leaveAnswerHayes 'CONNECT 1200
302: LOOK FOR "1^M", 1,3 THEN HOLD ON:GOTO leaveAnswerHayes 'CONNECT 300
autoAnswer2:
Status = "Waiting for Call"
TIMER RESET
TIMER START
endTime% = Now% + answerWait%
HOLD OFF
SET DBOX 499
DBOX 499
waitForCalls: ' Wait for call, user cancel, or time out
'{RTV 5/11/88}
IF (Now% > endTime%) AND (answerWait% <> -1) THEN GOTO answerTimeOut
IF DBoxResult% <> OK% THEN GOTO waitForCalls
CLEAR DBOX 499 'User clicked "Cancel" button
'{RTV - 5/17/88 - In case modem answered while clearing DBOX 499}
GOSUB HangUp
SEND "ATS0=0"
Message = "CANCEL"
Status = "Off Line"
TIMER STOP
TIMER RESET
CURSOR RESET
FORGET ALL
CommC.RemEcho% = SaveRemEcho% ' restore changed settings
CommC.DBits% = SaveDBits%
RETURN
answerTimeOut:
CLEAR DBOX 499
'{RTV - 5/17/88 - In case modem answered while we weren't looking}
GOSUB HangUp
SEND "ATS0=0"
Message = "TIMEOUT"
Status = "Off Line"
TIMER STOP
TIMER RESET
CURSOR RESET
FORGET ALL
CommC.RemEcho% = SaveRemEcho% ' restore changed settings
CommC.DBits% = SaveDBits%
RETURN
'If Fast XModem is checked and answered as CONNECT FAST then change to CRC XModem
'This is needed because TELEBIT's XModem spoof only works with 128 byte blocks
'If a Hayes is at other end and Fast XModem is checked then put back to 1K blocks XModem
'If FastXModem is not checked or TELEBIT to Hayes in selected then protocol is never changed
leaveAnswerPEP:
if (@modemMaxBPS% >= 9600) and @modemFastXModem% then ∂
CommC.ProtOpt% = 1
goto leaveAnswer
leaveAnswerHayes:
if (@modemMaxBPS% < 9600) and @modemFastXModem% then ∂
CommC.ProtOpt% = 2
leaveAnswer:
CLEAR DBOX 499
Status = "On Line"
TIMER RESET
TIMER START
CURSOR RESET
FORGET ALL
CommC.RemEcho% = SaveRemEcho% ' restore changed settings
CommC.DBits% = SaveDBits%
HOLD OFF
RETURN
'*******************************************************************************
Configure: 'get modem configuration and store in lookup table
'*******************************************************************************
HOLD ON
CURSOR WATCH
'Define default init strings
'{RTV 7/6/88 Added S7=40 to InitHayes}
InitHayes = "at v0 h0 s0=0 s7=40 s50=3 s54=3 s58=2"
InitPEP = "at v0 h0 s0=0 s7=60 s50=255 s54=3 s58=2"
InitUniv = "at v0 h0 s0=0 s7=60 s50=0 s54=3 s58=2 s92=1"
'Set defaults for undefined lookup table items
if @modemMaxBPS% = 0 then @modemMaxBPS% = 19200
if @modemInitHayes = "" then @modemInitHayes = InitHayes
if @modemInitPEP = "" then @modemInitPEP = InitPEP
if @modemInitUniv = "" then ∂
@modemInitUniv = InitUniv: ∂
@modemFastXModem% = TRUE% ' assume first TELEBIT run
SET DBOX 240 ' modem configure dbox
IF @modemMaxBPS% = 19200 THEN ∂
RadioCluster%(1) = 2: ∂
@modemInit = @modemInitPEP ∂
ELSE IF @modemMaxBPS% = 9600 THEN ∂
RadioCluster%(1) = 3: ∂
@modemInit = @modemInitUniv ∂
ELSE ∂
RadioCluster%(1) = 1: ∂
@modemInit = @modemInitHayes
DboxResp(1) = @modemInit
'Save RadioCluster%(1)'s original setting to see if user changes it
originalRC1% = RadioCluster%(1)
CheckBox%(1) = @modemCompression%
CheckBox%(2) = @modemFastXModem%
CheckBox%(3) = (UpCase(@modemDialPre) = "ATDT")
'Save user-entered text into temp strings in case CANCEL is pressed
'Initialize temporary strings here
TempHayes = @modemInitHayes
TempPEP = @modemInitPEP
TempUniv = @modemInitUniv
HOLD OFF
DBoxLoop:
DBOX 240
HOLD ON
IF originalRC1% <> RadioCluster%(1) THEN gosub UpdateDBox
IF DBoxResp(1) = "" then ∂
BELL:∂
IF RadioCluster%(1) = 1 THEN DBoxResp(1) = InitHayes ∂
ELSE IF RadioCluster%(1) = 2 THEN DBoxResp(1) = InitPEP ∂
ELSE DBoxResp(1) = InitUniv
HOLD OFF
dbr% = DBoxResult%
IF dbr% = CANCEL% THEN CLEAR DBOX 240: END 'user selected CANCEL
IF dbr% <> OK% THEN goto DBoxLoop
HOLD ON
CURSOR WATCH
IF originalRC1% = RadioCluster%(1) THEN gosub UpdateDBox
IF RadioCluster%(1) = 1 THEN ∂
@modemMaxBPS% = 2400: ∂
@modemInit = TempHayes ∂
ELSE IF RadioCluster%(1) = 2 THEN ∂
@modemMaxBPS% = 19200: ∂
@modemInit = TempPEP ∂
ELSE ∂
@modemMaxBPS% = 9600: ∂
@modemInit = TempUniv
'Write temporary strings back to lookup table
@modemInitHayes = TempHayes
@modemInitPEP = TempPEP
@modemInitUniv = TempUniv
@modemCompression% = CheckBox%(1)
@modemFastXModem% = CheckBox%(2)
IF CheckBox%(3) THEN @modemDialPre = "ATDT" ELSE @modemDialPre = "ATDP"
CLEAR DBOX 240
CURSOR RESET
HOLD OFF
RETURN
UpdateDBox:
IF originalRC1% = 1 THEN TempHayes = DBoxResp(1) ∂
ELSE IF originalRC1% = 2 THEN TempPEP = DBoxResp(1) ∂
ELSE TempUniv = DBoxResp(1) ∂
IF RadioCluster%(1) = 1 THEN DBoxResp(1) = TempHayes ∂
ELSE IF RadioCluster%(1) = 2 THEN DBoxResp(1) = TempPEP ∂
ELSE DBoxResp(1) = TempUniv
originalRC1% = RadioCluster%(1)
RETURN
ClearTable: 'clear all modem values from the lookup table
CLEAR @modemCustom% 'clear out old Hayes vars too just to keep table clean
CLEAR @modemMaxBPS%
CLEAR @modemDialPre
CLEAR @modemNumbers
CLEAR @modemRedial%
CLEAR @modemCommEnd%
CLEAR @modemCommEnd
CLEAR @modemEscape
CLEAR @modemGuardTime%
CLEAR @modemInit
CLEAR @modemInitHayes
CLEAR @modemInitPEP
CLEAR @modemInitUniv
CLEAR @modemHangUp
CLEAR @modemNoCarrier
CLEAR @modemBusy
CLEAR @modemCommAck
CLEAR @modemCommError
CLEAR @modemCompression%
CLEAR @modemFastXModem%
RETURN
'****************************************************************************
'Internal subroutines from this point to end of file
'These subroutines should not be called directly from an external program
'****************************************************************************
modemReset: 'Reset the modem and send the init string to the modem
HOLD OFF
if version% < 16809985 then ∂
dboxSay = "Sorry, the TELEBIT modem file will not work with older versions of Acknowledge.": ∂
dbox: ∂
end
IF (@modemMaxBPS% = 0) or (@modemInit = "") THEN GOSUB Configure
CURSOR PHONE
Status = "Resetting Modem"
CommC.DTR% = TRUE%
CommC.CTS% = TRUE%
'Compose modem initialization string
modemInit = @modemInit
if @modemMaxBPS% < 9600 then goto NoTelebitStuff
if @modemCompression% then modemInit = modemInit & "s110=1"
if @modemFastXModem% then modemInit = modemInit & "s111=20"
NoTelebitStuff:
resetTries% = 0 'Reset number of retries count
modemReset1:
gosub SetupLookfors 'Setup LOOK FOR "OK" and LOOK FOR "ERROR"
send modemInit 'If we're lucky, one of the LOOK FOR's will hit
idle 60
forget all
'{RTV 7/6/88}
'look for "0^M", 1, 5 then ∂
'gosub SetupLookfors: ∂
'send modemInit: ∂
'wait 1: ∂
'goto FindBaud
send "+++"; 'we weren't so lucky. Enter command state...
wait 1
'{RTV 7/6/88}
GOSUB SetupLookfors
SEND modemInit 'and try again. If we blow it here, then we'll have to
WAIT 1 'check the modem's baud
FindBaud:
'Still not responding, get Telebit set to a known baud rate
forget all
s = "^M^Mat &f v1"
look for "OK^M^J" then goto BaudFound
bps% = 19200: CommC.BPS% = bps%: send s: wait 1
bps% = 9600: CommC.BPS% = bps%: send s: wait 1
bps% = 2400: CommC.BPS% = bps%: send s: wait 1
bps% = 1200: CommC.BPS% = bps%: send s: wait 1
bps% = 300: CommC.BPS% = bps%: send s: wait 1
goto resetAgain 'Maybe RING RING is comming in, try again
BaudFound:
forget all
CommC.BPS% = 9600
idle 20
send "at s66=1 s51=5" 'Set modem to start up at 19200 (set s66 before s51!)
idle 20 'Wait for things to settle
CommC.BPS% = 19200 'Set Macintosh BPS to 19200
idle 20
SEND "at s66=1 s51=5" 'Set modem to start up at 19200 AGAIN
IDLE 20 'just in case we're connected (don't ask!)
send "at &W" 'Write settings to parameter RAM
idle 20
resetAgain: 'Try 5 times
resetTries% = resetTries% + 1
IF resetTries% < 5 THEN GOTO modemReset1 ∂
ELSE Message = "Modem not responding. Try turning modem power on and off." &∂
" Check modem connections.": ∂
GOSUB modemFatalError: ∂
GOTO modemReset
SetupLookfors:
'{RTV - 5/13/88 A Ring (2) may affect where the LOOK FOR is. Change to 1,5 vs. 1,1}
LOOK FOR "4^M",1,5 THEN ∂
Message = "Invalid modem command string." & ∂
"Please check phone number(s) and command strings and try again.": ∂
GOSUB modemFatalError:∂
GOTO modemReset
'{RTV - 5/13/88 A Ring (2) may affect where the LOOK FOR is. Change to 1,5 vs. 1,1}
LOOK FOR "0^M",1,5 THEN HOLD ON: ∂
Release: clreol: Message = "":FORGET ALL:FORGET ON:RETURN
RETURN
quickModemCommands: ' come here for non-custom modems
IF @modemMaxBPS% = 19200 THEN @modemInit = @modemInitPEP ∂
ELSE IF @modemMaxBPS% = 9600 THEN @modemInit = @modemInitUniv ∂
ELSE @modemInit = @modemInitHayes
quickHangUpCommands: ' for hanging up we don't need above variables
' save any comm settings that are changed
SaveRemEcho% = CommC.RemEcho%
SaveDBits% = CommC.DBits%
' Reset echo and dbits so that commands will work
CommC.RemEcho% = NO%
CommC.DBits% = 8
modemCommEnd = chr(13)
RETURN
parseAnswerMessage:
'Parses Message into modemAnswerRings and answerWait
modemAnswerRings = Message
answerWait = "-1" 'answerWait% = -1 if no value passed (so we wait forever)
' parse the node address into nodeAddress
messageLine% = INSTR%(Message,"|")
IF messageLine% <> 0 THEN ∂
modemAnswerRings = LEFT(Message, messageLine% - 1): ∂
answerWait = MID(Message, messageLine% + 1)
IF modemAnswerRings = "" THEN modemAnswerRings = "1"
Message = ""
RETURN
modemFatalError:
' This routine handles modem fatal errors.
' It displays a description of the error and then gives the user the ∂
' chance to correct the problem and try again or cancel the program.
Status = "Modem Error"
DBoxSay = Message ' Message contains the error
SET DBox 504
DBOX 504
IF DBoxResult% = OK% THEN ∂ ' user selected RETRY
Message = "":∂
CLEAR DBox 504 :∂
GOSUB quickModemCommands: ∂
GOSUB modemReset: ∂
RETURN ∂
ELSE ∂ ' user cancelled
CLEAR DBox 504: ∂
Message = "": ∂
Service = "": ∂
Network = "": ∂
CommC.RemEcho% = SaveRemEcho%: ∂ ' restore changed settings
CommC.DBits% = SaveDBits%: ∂
END
Interrupt: ' interrupts not allowed
BELL:BELL
RETURN